﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Practices.Unity;
using System.Reflection;
using Net;
namespace MDS
{
    public class MDSServer
    {
        IUnityContainer _container = new UnityContainer();
        Level1QuotationManager l1;

        public MDSServer()
        {
            registerAllConfigs();
            l1 = constructLevel1QuotManager();
        }

        public void Start()
        {
            l1.Start();
        }
        private void registerAllConfigs()
        {
            var allTypes = Assembly.GetCallingAssembly().GetTypes();
            foreach (var type in allTypes)
            {
                if (type.IsPublic
                    && type.BaseType == typeof(ConfigBase)
                    && type.IsAbstract ==false)
                {
                    _container.RegisterType(type);
                }
            }

        }

        private Level1QuotationManager constructLevel1QuotManager()
        {



            DBFQuotationProviderConfig shanghaiCfg=new DBFQuotationProviderConfig (@"C:\Dev\SinaQuotProxy\OutFile\SHOW2003.DBF",5000);
          
            GZLXInterestProvider  gzlxInterestProvider=new GZLXInterestProvider (new GZLXInterestProviderConfig(@"C:\Dev\SinaQuotProxy\OutFile\GZLX.DBF"));
            ShanghaiDBFQuotationProvider shanghaiQuot = new ShanghaiDBFQuotationProvider(shanghaiCfg, _container.Resolve<TradeRulesConfig>(), gzlxInterestProvider);

            DBFQuotationProviderConfig shenzhenCfg = new DBFQuotationProviderConfig(@"C:\Dev\SinaQuotProxy\OutFile\SJSHQ.DBF", 5000);
          
            SJSGFInterestProvider sjsgfInterestProvider = new SJSGFInterestProvider(new SJSGFInterestProviderConfig(@"C:\Dev\SinaQuotProxy\OutFile\SJSGF.dbf"));
            ShenzhenExtInfoProvider extInfoProvider = new ShenzhenExtInfoProvider(new ShenzhenExtInfoProviderConfig(@"C:\Dev\SinaQuotProxy\OutFile\SJSXXN.DBF", 5000 * 10));
            ShenzhenDBFQuotationProvider shenzhenQuot = new ShenzhenDBFQuotationProvider(shenzhenCfg, _container.Resolve<TradeRulesConfig>(), sjsgfInterestProvider, extInfoProvider);

            AggregatedQuotationProvider aqp = new AggregatedQuotationProvider(shanghaiQuot, shenzhenQuot);
            TradeDaysProvider tdp = new TradeDaysProvider(new TradeDaysProviderConfig());

            IRepositoryFactory repositoryFactory = new RaptorRepositoryFactory();



            Level1QuotationManager quotManager = new Level1QuotationManager(aqp, tdp, msgRep, level1BasicInfoSnapshot, level1BidSnapshot, level1TickSnapshot, 
                server);
            return quotManager;
        }
    }
}
